var app = angular.module("indexApp", []);
app.controller("indexCtrl", function ($scope, $http, $timeout, $interval) {  
    // 添加设备号
    var list = {};
    $scope.seltype = '1';
    $scope.add_dev = function(){
    	if ($scope.devid == null || $scope.devid == '') {
    		alert('请输入终端号');
    		return;
    	}
    	if (list[$scope.devid]) {
            alert('该终端号已存在');
    	}else{
    		list[$scope.devid] = $scope.devid;
            $scope.list = list;
    	}
       
    }
    // 发送命令
    $scope.send_data = function(){
    	if ($scope.seltype == null || $scope.seltype == '') {
    		alert('选择发送数据类型');
    		return;
    	}
    	var data = {
    		time:10000
    	}
    	if ($scope.send_time) {
            data.time = $scope.send_time;
    	}
    	
        $http.post(baseurl + "/command/"+$scope.seltype,data).then(function (res) {
	        // console.log(res.data);
	        $scope.senderdata = JSON.stringify(res.data.info.data);
	    });
    }
    // 接收终端数据
    var get_info = function(){
    	$http.get(baseurl + "/select_info").then(function (res) {
	        // console.log(res.data);
	        $scope.receivedata = JSON.stringify(res.data.info);
	    });
    }
    var timeout = $interval(get_info, 10000);
})

